package mobi.yuanshen.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import mobi.yuanshen.common.domain.dto.AliVodDTO;
import mobi.yuanshen.common.domain.dto.RequestUploadVideoDTO;
import mobi.yuanshen.common.utils.Result;
import mobi.yuanshen.service.FileService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.multipart.MultipartFile;

/**
 * 文件操作类,包括文件上传、视频上传等的接口
 */
@RestController
@RequestMapping("/fileops")
@Tag(name = "文件操作相关接口")
@RequiredArgsConstructor
@Slf4j
@CrossOrigin
public class FileController {

    private final FileService fileService;

    @PostMapping("/uploadFile")
    @Operation(summary = "上传文件")
    public Result<String> uploadFile (MultipartFile file) {
        return Result.success("文件url");
    }

    @PostMapping("/uploadVideo")
    @Operation(summary = "上传视频")
    public Result<String> uploadVideo (MultipartFile file) {
        return Result.success("视频url");
    }

    @PostMapping("/requestUploadVideo")
    @Operation(summary = "请求上传视频")
    public Result<AliVodDTO> requestUploadVideo (@RequestBody RequestUploadVideoDTO uploadVideoDTO) {
        AliVodDTO aliVodDTO = fileService.requestUploadVideo(uploadVideoDTO);
        log.info("客户端请求上传视频:{}", aliVodDTO);
        return Result.success(aliVodDTO);
    }
}
